#include "BlueprintScriptLibrary/BaseInc.h"
#include "BlueprintScriptLibrary/Reflections.h"
#include "MyClass.h"

RegisterBlueprintClass(MyClass)
BlueprintScriptLibrary::NativeMethodPin* ConstructSetVbiaMethod()
{
	std::function<void(MyClass*, BlueprintScriptLibrary::VarBaseInt)> f = std::bind(&MyClass::SetVbia, std::placeholders::_1, std::placeholders::_2);
	BlueprintScriptLibrary::NativeMethodPin* fp = new BlueprintScriptLibrary::NativeMethodPin;
	std::vector<BlueprintScriptLibrary::Var*> vbs;
	BlueprintScriptLibrary::Array<BlueprintScriptLibrary::Var> inputArray(1);
	std::function<BlueprintScriptLibrary::Var**(BlueprintScriptLibrary::Object*, BlueprintScriptLibrary::Var**)> func = [f](BlueprintScriptLibrary::Object* obj, BlueprintScriptLibrary::Var** input)->BlueprintScriptLibrary::Var** {
		MyClass* mc = dynamic_cast<MyClass*>(obj);
		BlueprintScriptLibrary::VarBaseInt* input0 = dynamic_cast<BlueprintScriptLibrary::VarBaseInt*>(input[0]);
		 f(mc, *input0);
		 return nullptr;
	};
	fp->Init("SetVbia", inputArray.data, NULL, func);
	return fp;
}
BlueprintScriptLibrary::NativeMethodPin* ConstructTrySetVbiaMethod()
{
	std::function<bool(MyClass*, BlueprintScriptLibrary::VarBaseInt)> f = std::bind(&MyClass::TrySetVbia, std::placeholders::_1, std::placeholders::_2);
	BlueprintScriptLibrary::NativeMethodPin* fp = new BlueprintScriptLibrary::NativeMethodPin;
	std::vector<BlueprintScriptLibrary::Var*> vbs;
	BlueprintScriptLibrary::Array<BlueprintScriptLibrary::Var> inputArray(1);
	BlueprintScriptLibrary::Array<BlueprintScriptLibrary::Var> outputArray(1);
	std::function<BlueprintScriptLibrary::Var**(BlueprintScriptLibrary::Object*, BlueprintScriptLibrary::Var**)> func = [&f](BlueprintScriptLibrary::Object* obj, BlueprintScriptLibrary::Var** input)->BlueprintScriptLibrary::Var** {
		MyClass* mc = dynamic_cast<MyClass*>(obj);
		BlueprintScriptLibrary::VarBaseInt* input0 = dynamic_cast<BlueprintScriptLibrary::VarBaseInt*>(input[0]);
		BlueprintScriptLibrary::Array<BlueprintScriptLibrary::Var> outputArray(1,false);
		//output
		BlueprintScriptLibrary::VarBaseBool* vb = new BlueprintScriptLibrary::VarBaseBool(false);
		*vb = f(mc, *input0);
		outputArray.data[0] = (BlueprintScriptLibrary::Var*)vb;
		return outputArray.data;
	};
	fp->Init("TrySetVbia", inputArray.data, outputArray.data, func);
	return fp;
}


BlueprintScriptLibrary::Class* MyClass::GetClass()
{
	using namespace BlueprintScriptLibrary;
//	g_AMFI.waitFreeMemPool[11] = 22;


	// std::vector<BlueprintScriptLibrary::NativeMembers*> v({ &vbia,&vbib,&vbic,&vbid});
	// std::vector<BlueprintScriptLibrary::NativeMembers*> v;
	 Array<NativeMembers>  arrMembers(4);
	 arrMembers.data[0]->Init("vbia", offsetof(MyClass, vbia),sizeof(vbia), vbia.GetType());
	 arrMembers.data[1]->Init("vbfb", offsetof(MyClass, vbfb), sizeof(vbfb), vbfb.GetType());
	 arrMembers.data[2]->Init("vbbc", offsetof(MyClass, vbbc), sizeof(vbbc), vbbc.GetType());
	 arrMembers.data[3]->Init("vbsd", offsetof(MyClass, vbsd), sizeof(vbsd), vbsd.GetType());
	 //v.push_back(BlueprintScriptLibrary::NativeMembers("vbia", offsetof(MyClass, vbia), "int"));
	 arrMembers.bGlobalScope = true;

	 //std::vector<BlueprintScriptLibrary::NativeMethodPin*> vmp;
	 ////BlueprintScriptLibrary::NativeMethodPin* nmp = new NativeMethodPin();
	 ////std::function<void(Object*, Var**)> f = std::bind1st(&MyClass::SetVbia, this, std::placeholders::_1);
	 //vmp.push_back(ConstructSetVbiaMethod());
	 //vmp.push_back(ConstructTrySetVbiaMethod());
	 Array<MethodPin> arrNativeMehtods(2,false);
	 arrNativeMehtods.bGlobalScope = true;
	 arrNativeMehtods.data[0] = ConstructSetVbiaMethod();
	 arrNativeMehtods.data[1] = ConstructTrySetVbiaMethod();
	// nmp->Init("SetVbia", NULL,NULL,);
	
	 //  BlueprintScriptLibrary::Class::BuildClass("MyClass", arrMembers.data, arrNativeMehtods.data);
	return BlueprintScriptLibrary::Class::BuildClassFromArray("MyClass", arrMembers, arrNativeMehtods);
}
